package com.heima.admin.controller.v1;

import com.heima.admin.service.ChannelService;
import com.heima.model.admin.dtos.ChannelDTO;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Program: day57-leadnews
 * @Description: 频道列表
 * @Data: 2022/7/25 21:59
 **/
@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理",tags ="频道管理",description = "频道管理API")
public class ChannelController {

    @Autowired
    private ChannelService channelService;


    @ApiOperation("根据id查询频道")
    @GetMapping("/one/{id}")
    public ResponseResult findOne(@PathVariable Integer id) {
        return ResponseResult.okResult(channelService.getById(id));
    }

    @PostMapping("/list")
    @ApiOperation("频道分页列表查询")
    public ResponseResult findPage(@RequestBody ChannelDTO dto){
        return channelService.pageQuery(dto);
    }

    @PostMapping("/save")
    @ApiOperation("频道新增")
    public ResponseResult insert(@RequestBody AdChannel channel){
        return channelService.insert(channel);
    }

    @PostMapping("/update")
    @ApiOperation("频道修改&频道有效无效设置")
    public ResponseResult update(@RequestBody AdChannel channel){
        return channelService.update(channel);
    }

    @GetMapping("/del/{id}")
    @ApiOperation("频道删除")
    public ResponseResult delete(@PathVariable Integer id){
        return channelService.deleteById(id);
    }

    /**
     * 查询所有频道的数据
     */
    @ApiOperation("查询全部频道")
    @GetMapping("/channels")
    public ResponseResult findAll() {
        List<AdChannel> list = channelService.list();
        return ResponseResult.okResult(list);
    }
}
